package com.javaclimb.music.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javaclimb.music.dao.ListSongMapper;
import com.javaclimb.music.domain.ListSong;
import com.javaclimb.music.service.ListSongService;
import com.javaclimb.music.utils.PageUtils;
import com.javaclimb.music.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ListSongServiceImpl extends ServiceImpl<ListSongMapper, ListSong> implements ListSongService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        LambdaQueryWrapper<ListSong> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank((CharSequence) params.get("songListId"))) {
            wrapper.eq(ListSong::getSongListId, params.get("songListId"));
        }

        //是否进行分页
        boolean isPage = false;
        if (StringUtils.isNotBlank((CharSequence) params.get("isPage"))) {
            isPage = Boolean.parseBoolean(String.valueOf(params.get("isPage")));
        }
        PageUtils pageUtils = null;
        if (isPage) {
            IPage<ListSong> page = this.page(new Query<ListSong>().getPage(params), wrapper);
            pageUtils = new PageUtils(page);
        } else {
            List<ListSong> list = this.list(wrapper);
            pageUtils = new PageUtils(list, 0, 0, 0);
        }
        return pageUtils;

    }
}
